public class Account {

    private String name;
    private double balance;//余额
    private String password;

    //无参构造
    public Account() {
    }
    //有参构造
    public Account(String name, double balance, String password) {
        this.setName(name);
        this.setBalance(balance);
        this.setPassword(password);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
    if(name.length() == 2 || name.length() == 3 || name.length() == 4){
        this.name = name;
    }else{
        System.out.println("你输入的名字有误，名字的为2到4个字符");
        this.name = "无名士";
    }
    }
    public double getBalance() {
        return balance;
    }


    public void setBalance(double balance) {
        if(balance > 20){
            this.balance = balance;
        }else{
            System.out.println("余额必须大于等于20");
            this.balance = 20;
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if(password.length() == 6){
            this.password = password;
        }else{
            System.out.println("密码有误，密码必须是六位，默认是000000");
            this.password = "000000";
        }
    }

    public void showInfo(){//显示账号信息
        //可增加权限的校验
        System.out.println("name=" + name + " balance=" + balance + " password=" + password);
//        if(){
//            System.out.println("name=" + name + " balance=" + balance + " password=" + password);
//        }else{
//            System.out.println("你无权查看");
//        }
    }
}
